﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SYS.Web.Runtime;
using SYS.Common.Runtime;
using ExpertMIS.Entities;
using ExpertMIS.Brokers;

namespace ExpertMIS.Forums
{
    public partial class Register : System.Web.UI.Page
    {
        protected HttpEnvironment Environment
        {
            get
            {
                return (HttpEnvironment)EnvironmentFactory.CreateEnvironment(EnvironmentType.ASPDotNet);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ucQuickRegister1.OnRegister += new ExpertMIS.Forums.UserControl.RegisterActionDelegate(ucQuickRegister1_OnRegister);
            if (Master is Visitor)
            {
                (Master as Visitor).Subtitle = "新用户注册";
            }
        }

        void ucQuickRegister1_OnRegister(object sender, bool success, string account, string failedReason)
        {
            if (success)
            {
                ADMUserBroker userBroker = new ADMUserBroker();
                ADMUserEntity user = userBroker.GetUserByAccount(account);
                ExpertMIS.Codes.Utility.GetEnvironment().UserLogon(user);
                Response.Redirect("../Workships/Default.aspx");
                Response.End();
            }
            else
            {
                // TODO, 注册失败后的原因显示
                lblReason.Text = failedReason;
            }
        }
    }
}
